package com.st.event.demo.config;

import com.st.event.demo.source.EventAnnotationSourceParser;
import com.st.event.demo.source.EventAttributeSource;
import com.st.event.demo.source.impl.DefaultEventAnnotationSourceParser;
import com.st.event.demo.source.impl.DefaultEventAttributeSource;
import com.st.event.demo.strategy.StrategyHandler;
import com.st.event.demo.strategy.builder.DefaultHandlerFactoryBuilder;
import com.st.event.demo.strategy.builder.HandlerFactoryBuilder;
import com.st.event.demo.strategy.handler.TestHandler;
import com.st.event.demo.strategy.impl.EventStrategyManager;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class SourceConfig {

    @Bean
    public EventAttributeSource eventAttributeSource(ObjectProvider<List<EventAnnotationSourceParser>> objectProvider) {
        System.out.println("zhuru ioc -------------");
        return new DefaultEventAttributeSource(objectProvider.getIfAvailable());
    }

    @Bean
    public EventAnnotationSourceParser defaultEventAnnotationSourceParser() {
        return new DefaultEventAnnotationSourceParser();
    }

    @Bean
    public EventStrategyManager eventStrategyManager(HandlerFactoryBuilder factoryBuilder, ObjectProvider<List<StrategyHandler>> strategyHandlers) {
      //  System.out.println("zhuru ioc -------------");
        return new EventStrategyManager(factoryBuilder, strategyHandlers.getIfAvailable());
    }

    @Bean
    public HandlerFactoryBuilder handlerFactoryBuilder() {
      //  System.out.println("zhuru ioc -------------");
        return new DefaultHandlerFactoryBuilder();
    }

    @Bean
    public TestHandler testHandler() {
        return new TestHandler();
    }

}
